package com.wolfcode.goods.controller;

import com.wolfcode.common.annotation.Log;
import com.wolfcode.common.core.controller.BaseController;
import com.wolfcode.common.core.domain.AjaxResult;
import com.wolfcode.common.core.page.TableDataInfo;
import com.wolfcode.common.enums.BusinessType;
import com.wolfcode.goods.domain.GoodsCategory;
import com.wolfcode.goods.domain.vo.GoodsCategoryVo;
import com.wolfcode.goods.service.IGoodsCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 物品分类信息Controller
 * 
 * @author sitia
 * @date 2022-12-10
 */
@RestController
@RequestMapping("/goods/category")
public class GoodsCategoryController extends BaseController
{
    @Autowired
    private IGoodsCategoryService goodsCategoryService;

    /**
     * 查询物品分类信息列表
     */
    @PreAuthorize("@ss.hasPermi('goods:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(GoodsCategoryVo goodsCategory)
    {
        startPage();
        List<GoodsCategory> list = goodsCategoryService.selectGoodsCategoryList(goodsCategory);
        return getDataTable(list);
    }



    /**
     * 获取物品分类信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('goods:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(goodsCategoryService.selectGoodsCategoryById(id));
    }

    /**
     * 新增物品分类信息
     */
    @PreAuthorize("@ss.hasPermi('goods:category:add')")
    @Log(title = "物品分类信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GoodsCategoryVo goodsCategoryVo)
    {
        return toAjax(goodsCategoryService.insertGoodsCategory(goodsCategoryVo));
    }

    /**
     * 修改物品分类信息
     */
    @PreAuthorize("@ss.hasPermi('goods:category:edit')")
    @Log(title = "物品分类信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GoodsCategory goodsCategory)
    {
        return toAjax(goodsCategoryService.updateGoodsCategory(goodsCategory));
    }

    /**
     * 删除物品分类信息
     */
    @PreAuthorize("@ss.hasPermi('goods:category:remove')")
    @Log(title = "物品分类信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable Integer id) throws Exception {
        return toAjax(goodsCategoryService.deleteGoodsCategoryByIds(id));
    }


    /**
     * 获取分级信息
     */
    @PreAuthorize("@ss.hasPermi('goods:category:query')")
    @GetMapping("/getBusiPath")
    public AjaxResult getBusiPath()
    {
        return AjaxResult.success(goodsCategoryService.getBusiPath());
    }
}
